package cn.itcast.web.controller.cargo;

import cn.itcast.domain.cargo.Contract;
import cn.itcast.domain.cargo.ContractExample;
import cn.itcast.service.cargo.ContractService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("cargo/audit")
public class AuditController extends BaseController {
    @Reference
    ContractService contractService;
    @RequestMapping(value = "list",name = "查看需要审核的合同")
    public String findAll(
            @RequestParam(defaultValue = "1")int page,
            @RequestParam(defaultValue = "10")int size
    ){
        ContractExample contractExample = new ContractExample();
        ContractExample.Criteria criteria = contractExample.createCriteria();
        criteria.andCompanyIdEqualTo(getCompanyId());
        criteria.andStateEqualTo(5);

        contractExample.setOrderByClause("ship_time desc");
        PageInfo pageInfo = contractService.findAll(page, size, contractExample);
        request.setAttribute("page",pageInfo);
        return "cargo/contract/contractAudit-list";
    }
    @RequestMapping(value = "submit",name = "审核通过")
    public String submit(String id){
        Contract contract = contractService.findById(id);
        contract.setState(1);
        System.out.println(contract.getCompanyName());
        contractService.update(contract);
        return "redirect:/cargo/audit/list.do";
    }


    @RequestMapping(value = "cancel",name = "审核取消")
    public String cancel(String id){
        Contract contract = contractService.findById(id);
        contract.setState(0);
        System.out.println(contract.getCompanyName());
        contractService.update(contract);
        return "redirect:/cargo/audit/list.do";
    }
}
